package com.per.mybootall.common;

import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.json.JsonXContent;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: yyy
 * Date: 2022/5/23
 * Time: 10:18
 * Description:
 */
//@Component
public enum TableEnum {
    USER("user") {
        @Override
        public XContentBuilder getMapping() throws IOException {
            return JsonXContent.contentBuilder()
                    .startObject()
                    .startObject("properties")
                    .startObject("id").field("type", "keyword").endObject()
                    .startObject("class_id").field("type", "keyword").endObject()
                    .startObject("teacher_name").field("type", "text").endObject()
                    .endObject()
                    .endObject();
        }
    },
    TEACHER("teacher") {
        @Override
        public XContentBuilder getMapping() throws IOException {
            return JsonXContent.contentBuilder()
                    .startObject()
                    .startObject("properties")
                    .startObject("id").field("type", "keyword").endObject()
                    .startObject("class_id").field("type", "keyword").endObject()
                    .startObject("teacher_name").field("type", "text").endObject()
                    .endObject()
                    .endObject();
        }
    },
    USER_CLASS("user_class") {
        @Override
        public XContentBuilder getMapping() throws IOException {
            return JsonXContent.contentBuilder()
                    .startObject()
                        .startObject("properties")
                        .startObject("id").field("type", "keyword").endObject()
                        .startObject("user_id").field("type", "keyword").endObject()
                        .startObject("user_class_name").field("type", "text").endObject()
                        .startObject("user_tearch_id").field("type", "keyword").endObject()
                        .endObject()
                    .endObject();
        }
    },
    ODR_ORDER_GOODSORDER("odr_order_goodsorder") {
        @Override
        public XContentBuilder getMapping() throws IOException {
            return JsonXContent.contentBuilder()
                    .startObject()
                    .startObject("properties")
                    .startObject("id").field("type", "keyword").endObject()
                    .startObject("version").field("type", "keyword").endObject()
                    .startObject("deleted").field("type", "keyword").endObject()
                    .startObject("createdBy").field("type", "keyword").endObject()
                    .startObject("creator").field("type", "text").endObject()
                    .startObject("createTime").field("type", "keyword").endObject()
                    .startObject("lastModifiedBy").field("type", "keyword").endObject()
                    .startObject("lastModifier").field("type", "text").endObject()
                    .startObject("lastModifiedDate").field("type", "keyword").endObject()
                    .startObject("appId").field("type", "keyword").endObject()
                    .startObject("orderId").field("type", "keyword").endObject()
                    .startObject("orderNumber").field("type", "keyword").endObject()
                    .startObject("orderType").field("type", "keyword").endObject()
                    .startObject("staffId").field("type", "keyword").endObject()
                    .startObject("staffName").field("type", "text").endObject()
                    .startObject("merchantId").field("type", "keyword").endObject()
                    .startObject("merchantName").field("type", "text").endObject()
                    .startObject("consumerId").field("type", "keyword").endObject()
                    .startObject("consumerAccountName").field("type", "text").endObject()
                    .startObject("consumerPhone").field("type", "text").endObject()
                    .startObject("consumerName").field("type", "text").endObject()
                    .startObject("consumerPostalcode").field("type", "text").endObject()
                    .startObject("consumerProvince").field("type", "keyword").endObject()
                    .startObject("consumerCity").field("type", "keyword").endObject()
                    .startObject("consumerArea").field("type", "keyword").endObject()
                    .startObject("consumerDetailAddr").field("type", "keyword").endObject()
                    .startObject("consumerLevelId").field("type", "keyword").endObject()
                    .startObject("consumerLevelName").field("type", "text").endObject()

                    .startObject("consumerSelectDeliver").field("type", "keyword").endObject()
                    .startObject("goodsType").field("type", "keyword").endObject()
                    .startObject("goodsTotalNumber").field("type", "keyword").endObject()
                    .startObject("orderStatus").field("type", "keyword").endObject()
                    .startObject("orderDeliverStatus").field("type", "keyword").endObject()
                    .startObject("orderDeliverWay").field("type", "text").endObject()
                    .startObject("orderTakeTime").field("type", "keyword").endObject()
                    .startObject("orderConsumeTime").field("type", "text").endObject()
                    .startObject("orderSpendWay").field("type", "text").endObject()
                    .startObject("orderGoodsAmount").field("type", "keyword").endObject()
                    .startObject("orderCarriage").field("type", "keyword").endObject()
                    .startObject("orderCategoryDiscountNum").field("type", "keyword").endObject()
                    .startObject("orderCategoryDiscountAmount").field("type", "keyword").endObject()
                    .startObject("orderAcitivityId").field("type", "keyword").endObject()
                    .startObject("orderActivityName").field("type", "text").endObject()
                    .startObject("orderActivityRule").field("type", "text").endObject()
                    .startObject("orderActivityDiscountNum").field("type", "keyword").endObject()
                    .startObject("orderActivityDiscountAmount").field("type", "keyword").endObject()
                    .startObject("orderConsumerDiscountNum").field("type", "keyword").endObject()
                    .startObject("orderConsumerDiscountAmount").field("type", "keyword").endObject()
                    .startObject("changePriceDiscount").field("type", "keyword").endObject()
                    .startObject("orderCouponName").field("type", "text").endObject()

                    .startObject("orderCouponDiscountAmount").field("type", "keyword").endObject()
                    .startObject("orderCouponTotalNumber").field("type", "keyword").endObject()
                    .startObject("orderVoucherAmount").field("type", "keyword").endObject()
                    .startObject("orderVoucherIds").field("type", "text").endObject()
                    .startObject("orderSumAmount").field("type", "keyword").endObject()
                    .startObject("orderDiscountAmount").field("type", "keyword").endObject()
                    .startObject("orderActualAmount").field("type", "keyword").endObject()
                    .startObject("orderMerchantRemark").field("type", "text").endObject()
                    .startObject("orderRemark").field("type", "text").endObject()
                    .startObject("orderConsumerPayStatus").field("type", "text").endObject()
                    .startObject("orderConsumerPayAmount").field("type", "keyword").endObject()
                    .startObject("orderConsumerPayWay").field("type", "text").endObject()

                    .startObject("orderConsumerPayTime").field("type", "keyword").endObject()
                    .startObject("orderConsumerPayNumber").field("type", "keyword").endObject()
                    .startObject("orderGiveIntegral").field("type", "keyword").endObject()
                    .startObject("orderUseIntegral").field("type", "text").endObject()
                    .startObject("receiverId").field("type", "keyword").endObject()
                    .startObject("receiverName").field("type", "text").endObject()
                    .startObject("receiverPhone").field("type", "keyword").endObject()
                    .startObject("receiverPostalcode").field("type", "keyword").endObject()
                    .startObject("receiverProvinceCode").field("type", "text").endObject()
                    .startObject("receiverCityCode").field("type", "text").endObject()
                    .startObject("receiverAreaCode").field("type", "text").endObject()
                    .startObject("receiverCityName").field("type", "text").endObject()
                    .startObject("receiverDetailAddr").field("type", "text").endObject()
                    .startObject("logisticsCompany").field("type", "text").endObject()
                    .startObject("logisticsNo").field("type", "keyword").endObject()
                    .startObject("logisticsType").field("type", "text").endObject()
                    .startObject("deletedReason").field("type", "text").endObject()
                    .startObject("deletedStaffName").field("type", "text").endObject()
                    .startObject("deletedStaffId").field("type", "keyword").endObject()
                    .startObject("authorizerName").field("type", "text").endObject()
                    .startObject("authorizerId").field("type", "keyword").endObject()
                    .startObject("deletedTime").field("type", "keyword").endObject()
                    .startObject("closedReason").field("type", "text").endObject()
                    .startObject("cancelReason").field("type", "text").endObject()
                    .startObject("afterSale").field("type", "keyword").endObject()
                    .startObject("companyId").field("type", "keyword").endObject()
                    .startObject("siteId").field("type", "keyword").endObject()
                    .startObject("siteName").field("type", "text").endObject()
                    .startObject("orgId").field("type", "keyword").endObject()
                    .startObject("orgName").field("type", "text").endObject()
                    .startObject("consumerNo").field("type", "keyword").endObject()
                    .startObject("consumerCard").field("type", "keyword").endObject()
                    .startObject("consumerCardFaceNo").field("type", "keyword").endObject()

                    .startObject("consumerLevelType").field("type", "keyword").endObject()
                    .startObject("consumerProviceCode").field("type", "keyword").endObject()
                    .startObject("consumerCityCode").field("type", "keyword").endObject()
                    .startObject("consumerAreaCode").field("type", "keyword").endObject()
                    .startObject("sendCouponIds").field("type", "text").endObject()
                    .startObject("normalValue").field("type", "text").endObject()
                    .startObject("normalUnit").field("type", "text").endObject()
                    .startObject("goodsTotalNumberByWeight").field("type", "keyword").endObject()
                    .startObject("orderConsumerPayAccount").field("type", "keyword").endObject()
                    .startObject("orderConsumerPayKey").field("type", "keyword").endObject()
                    .startObject("orderConsumerPaySecret").field("type", "keyword").endObject()
                    .startObject("reservationServiceTime").field("type", "keyword").endObject()
                    .startObject("receiverSiteId").field("type", "keyword").endObject()
                    .startObject("receiverRegionId").field("type", "keyword").endObject()
                    .startObject("workOrderId").field("type", "keyword").endObject()
                    .startObject("divFee").field("type", "keyword").endObject()
                    .startObject("divChannelFee").field("type", "keyword").endObject()
                    .startObject("divPlateAmt").field("type", "keyword").endObject()
                    .startObject("divMerchantAmt").field("type", "keyword").endObject()
                    .startObject("divOtherMerchantAmt").field("type", "keyword").endObject()
                    .startObject("divAccountAmt").field("type", "keyword").endObject()
                    .startObject("divStatus").field("type", "keyword").endObject()
                    .startObject("onAccountCompanyName").field("type", "keyword").endObject()
                    .startObject("onAccountDepartmentName").field("type", "keyword").endObject()
                    .startObject("onAccountPersonName").field("type", "keyword").endObject()
                    .startObject("onAccountPersonPhone").field("type", "keyword").endObject()
                    .startObject("orderFromSystem").field("type", "keyword").endObject()
                    .startObject("associatedMerchantIds").field("type", "keyword").endObject()
                    .endObject()
                    .endObject();
        }
    };
    private final String name;

    TableEnum(String name) {

        this.name = name;
    }

    public String getName() {
        return name;
    }


    public static TableEnum getEnumByName(String tableName) {
        for (TableEnum type : TableEnum.values()) {
            if (type.getName().equals(tableName)) {
                return type;
            }
        }
        return null;
    }

    public abstract XContentBuilder getMapping() throws IOException;
}
